package com.xliu.cs.openproject.lianliankan;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import lombok.Getter;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.List;

@Getter
@Setter
public class Config {
    private static final Logger LOG = LoggerFactory.getLogger(Config.class);

    private List<Link> links;
    private About about;
    private BarCode barCode;
    private String title;
    private String bgImagePath;
    private String unfinishedMsg;
    private String musicPath;

    private static Config config = init();

    public static Config getInstance() {
        return config;
    }

    public static Config init() {
        ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());

        try {
            String configFile = Config.class.getClassLoader().getResource("config.yaml").getFile();
            return objectMapper.readValue(new File(configFile), Config.class);
        } catch (Exception e) {
            LOG.error("read config file error, quit", e);
            System.exit(-1);
        }
        return null;
    }

    @Getter
    @Setter
    public static class Link {
        private String name;
        private String site;
    }

    @Getter
    @Setter
    public static class About {
        private String message;
        private String title;
    }


    @Getter
    @Setter
    public static class BarCode {
        private String content;
        private String iconPath;
        private String checkMsg;
        private String checkFailedMsg;
        private String checkSuccMsg;
    }
}
